package servlets;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;
import org.osgi.util.tracker.ServiceTracker;
public class HttpServiceTracker extends ServiceTracker{
    public HttpServiceTracker(BundleContext context) {
        super(context, HttpService.class.getName(), null);
    }
    public Object addingService(ServiceReference reference) {
        HttpService httpService = (HttpService) context.getService(reference);
        try {
            httpService.registerResources("/index.html", "/index.html", null);
            httpService.registerResources("/style.css", "/style.css", null);
            httpService.registerResources("/images", "/images", null);
            httpService.registerResources("/JavaScript", "/JavaScript", null);
            httpService.registerServlet("/MediConflict", new MediConflictServlet(), null, null);
            httpService.registerServlet("/Login", new LoginServlet(), null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return httpService;
    }
    public void removedService(ServiceReference reference, Object service) {
        HttpService httpService = (HttpService) service;
        httpService.unregister("/index.html");
        httpService.unregister("/MediConflict");
        httpService.unregister("/Login");
        super.removedService(reference, service);
    }
}